package com.sh.sales.happysales.app;


import android.database.sqlite.SQLiteDatabase;

import com.sh.polymedicine.happysale.Interceptor.HeaderInterceptor;
import com.sh.sales.happysales.app.utils.LoginUtil;
import com.sh.sales.happysales.imgutil.LoadImageManager;
import com.sh.polymedicine.happysale.service.envelop.HappySaleManager;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;

import org.litepal.LitePalApplication;
import org.litepal.tablemanager.Connector;

/**
 * Created by zhouyucheng on 2017/8/3.
 */

public class AppContext extends LitePalApplication {
    private static IWXAPI iwxapi;

    public static IWXAPI getIwxapi() {
        return iwxapi;
    }

    private static AppContext m;

    public static AppContext getInstance() {
        return m;
    }

    @Override
    public void onCreate() {
        registWeChart();
        m = this;
        SQLiteDatabase db = Connector.getDatabase();
        LoadImageManager.getInstance(m).setImgPortalAddress(AppCondig.PICADDRESS);
        HappySaleManager.Builder builder = new HappySaleManager.Builder();
        builder.portalAddress(AppCondig.PORTALADDRESS);
        builder.AccessTokenRfresh(new HeaderInterceptor.AccessTokenRfresh() {
            @Override
            public void accessToken(String accessToken) {
                System.out.println("accessToken刷新==》："+accessToken);
                AppData.getInstence().getmUserToken().setAccessToken(accessToken);
                LoginUtil.getInstance().catchUserInfo(AppData.getInstence().getmUserToken(), m, 2);
            }
        });
        builder.build();
        super.onCreate();
    }

    private void registWeChart() {
        iwxapi = WXAPIFactory.createWXAPI(this, AppCondig.WX_APPID, true);
        iwxapi.registerApp(AppCondig.WX_APPID);
    }
}
